﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sasa.QualityTools.CodeAnalysis.Core.VisualStudio;
using Sasa.QualityTools.CodeAnalysis.Core.Models;
using System.IO;

namespace Sasa.QualityTools.CodeAnalysis.Core.Utilities
{
    public static class MetricsOptionBuilder
    {

        public static string Build(IProject project, Version version)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            if (version == null)
            {
                throw new ArgumentNullException("version");
            }

            var config = CodeAnalysisConfiguration.Load(project.ConfigurationPath);
            config.Override(CodeAnalysisConfiguration.Load(project.Solution.ConfigurationPath));

            var result = new List<string>();

            result.Add("/f:" + '"' + project.AssemblyPath + '"');
            result.Add("/o:" + '"' + Path.Combine(project.TargetDir, Constants.CodeMetricsReportFileName) + '"');
            result.Add("/sf");

            if (config.EnableSearchGac)
            {
                result.Add("/gac");
            }

            if (config.IgnoreGeneratedCode)
            {
                result.Add("/igc");
            }

            foreach (var dir in project.DependencyDirectories)
            {
                result.Add("/d:" + '"' + dir.TrimEnd('\\') + '"');
            }

            return String.Join<string>(" ", result);
        }
    }
}
